<template>
  <!-- :class="[{'iphonex-top' : isIphoneX}]"  -->
  <div class="nav-bar z-index-max" :style="navBarStyle">
    <div class="left" @click="$emit('onLeftClick')">
      <!-- 默认状态 -->
      <img v-if="isDefault && isShowBack" src="@/assets/images/icon_back.png" alt="" srcset="">
      <!-- 定制具名插槽 -->
      <slot name="nav-left"></slot>
    </div>
    <div class="center">
      <!-- 默认状态 -->
      <span class="page-title" v-if="isDefault">{{pageName}}</span>
      <!-- 定制具名插槽 -->
      <slot name="nav-center"></slot>
    </div>
    <div class="right fl end">
      <!-- 定制具名插槽 -->
      <slot name="nav-right"></slot>
    </div>
  </div>
</template>


<script>
export default {
  props: {
    // 是否展示默认状态
    isDefault: {
      default: true,
      type: Boolean
    },
    // 是否展示默认后退按钮
    isShowBack: {
      default: true,
      type: Boolean
    },
    // 默认状态下页面标题的名称
    pageName: {
      default: '',
      type: String
    },
    // navBar样式
    navBarStyle: {
      type: Object,
      default: function () {
        return {
          backgroundColor: 'white'
        }
      }
    }
  },
  data: function () {
    return {
      isIphoneX: window.isIphoneX,
      navigationHeight: 0,
      statusBarHeight: 0
    }
  }
}
</script>


<style lang="less" scoped>
.iphonex-top {
  padding-top: 44px !important;
}
.nav-bar {
  width: 100%;
  // height: 47px;
  // line-height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  // 适配手机 stateBar 
  // padding-top: 24px;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9;
  .left, .right {
    width: 30%;
    display: flex;
    align-items: center;
    height: 100%;
    img {
      width: 24px;
      height: 24px;
      // align-self: center;
    }
  }
  .left {
    // width: 30px;
    padding-left: 20px;
  }
  .right {
    // width: 30px;
    padding-right: 20px;
  }
  .center {
    display: flex;
    height: 100%;
    flex-grow: 1;
    .page-title {
      align-self: center;
      margin: 0 auto;
      font-size: 16px;
      font-weight: bold;
    }
  }
}
</style>
